<?php
	/**
	 * 
	 * 留言系统
	 * @author xie.noah
	 *
	 */
	class CommentAction extends CommonAction {
		/**
		 * 
		 * 保存评论
		 */
		public function SaveComment() {
			//得到目标评论信息
			$id = $_REQUEST ['id'];
			$content = $_REQUEST ['content'];
			$model = M ( "user_comment" );
			$data ["product_id"] = $id;
			$data ["content"] = $content;
			$data["comment_user"] =  Session::get(C('USER_AUTH_KEY')) ;
			$data ["createdate"] = date('Y-m-d H:i:s',time());
		 	
			//插入信息到数据库
			$result = $model->add($data);
		 
			$msg = ""  ;
			
			//打印插入成功与否
			if ($result==false){
				$msg = "新增评论失败！" . $model->getError();
			}else {
				$msg = "新增评论成功！";
			}
			$this->ajaxReturn ( "111111", $msg, 1 );
			}
		
		/**
		 * 
		 * 展示所有评论
		 */
		public function ShowDetails() {
			//从数据库读取表内信息
			$comment_model = M ("user_comment") ;
			$id = $_REQUEST ['id'];
			$comment_condition['product_id'] = $id;
			
			//查询表内数据，按时间降序排列
			$comment_list = $comment_model->where($comment_condition)->order('createdate desc')->select();
			
			//将所得数据打包传到HTML
			$this->assign ( "comment_list", $comment_list );
		}
	}
?>
